//
//  MoreMessageVC.m
//  MRBang
//
//  Created by 铅笔 on 16/4/21.
//  Copyright © 2016年 杭州易网新科技. All rights reserved.
//

#import "MoreMessageVC.h"
#import "RXDAboutController.h"//关于我们
#import "SuggestViewController.h"//意见反馈
#import "HelpCenterVC.h"//帮助中心
#import "RecomAwardVC.h"//推荐有奖

@interface MoreMessageVC ()<UITableViewDataSource,UITableViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIActionSheetDelegate>

{
    UIButton *button_send;
    BOOL isOpen;

}
@property (nonatomic,strong) UITableView *tableView_moreMessage;

@end

@implementation MoreMessageVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"关于MR帮";
    
    self.view.backgroundColor = COLOR_EVERYVIEWBG;
    
    [self initWithMoreMessageVCSubviews];
}

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    self.tabBarController.tabBar.hidden = YES;
}

#pragma mark ---- 创建子视图
- (void) initWithMoreMessageVCSubviews
{
    self.tableView_moreMessage = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-64)];
    [self.view addSubview: self.tableView_moreMessage];
    self.tableView_moreMessage.dataSource = self;
    self.tableView_moreMessage.delegate = self;
    self.tableView_moreMessage.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView_moreMessage.showsVerticalScrollIndicator = NO;
    self.tableView_moreMessage.scrollEnabled = NO;
    self.tableView_moreMessage.backgroundColor = COLOR_EVERYVIEWBG;
    
}

#pragma mark --- UITableViewDatasource
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *perID = @"peronsCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:perID];
    
    if (cell==nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:perID];
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    //横线
    UIView *view_line = [[UIView alloc] init];
    [cell.contentView addSubview:view_line];
    view_line.backgroundColor = RXDColor(242, 242, 242);
    
    view_line.frame = CGRectMake(0,95*PROPORTION_WIDTH-1.0, kScreenWidth, 1.0);
    
    NSArray *array_avatar = @[@"帮助中心",@"意见反馈",@"联系我们",@"推荐有奖",@"关于我们",@"信息推送"];
    
    UILabel *label_avatar = [[UILabel alloc] initWithFrame:CGRectMake(47*PROPORTION_WIDTH, 36*PROPORTION_WIDTH, 456*PROPORTION_WIDTH, 34*PROPORTION_WIDTH)];
    [cell.contentView addSubview:label_avatar];
    label_avatar.text = array_avatar[indexPath.row];
    label_avatar.font = [UIFont systemFontOfSize:24*PROPORTION_WIDTH];
    
    UIImageView *imageView_arrow;
    
    if (indexPath.row!=5) {
        //右侧箭头
        imageView_arrow = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth-49*PROPORTION_WIDTH, 33*PROPORTION_WIDTH, 30*PROPORTION_WIDTH, 31*PROPORTION_WIDTH)];
        [cell.contentView addSubview:imageView_arrow];
        imageView_arrow.image = [UIImage imageNamed:@"return_right"];
    }
    if (indexPath.row==5) {
        //开启推送
//        imageView_arrow = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth-113*PROPORTION_WIDTH, 33*PROPORTION_WIDTH, 83*PROPORTION_WIDTH, 35*PROPORTION_WIDTH)];
//        [cell.contentView addSubview:imageView_arrow];
//        imageView_arrow.image = [UIImage imageNamed:@"unsend"];
        
        button_send = [[UIButton alloc] initWithFrame:CGRectMake(kScreenWidth-113*PROPORTION_WIDTH, 33*PROPORTION_WIDTH, 83*PROPORTION_WIDTH, 35*PROPORTION_WIDTH)];
        [cell.contentView addSubview:button_send];
        [button_send setBackgroundImage:[UIImage imageNamed:@"unsend"] forState:UIControlStateNormal];
        
        isOpen = NO;
        
        [button_send addTarget:self action:@selector(useSendYesOrNoAction) forControlEvents:UIControlEventTouchUpInside];
    }
    
    if (indexPath.row==2) {
        //右侧 显示label
        UILabel *label_titleRight = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth/2-40, 6, kScreenWidth/2+10, 30)];
        [cell.contentView addSubview:label_titleRight];
        label_titleRight.textColor = RXDColor(207, 207, 207);
        label_titleRight.font = [UIFont systemFontOfSize:13];
        label_titleRight.textAlignment = NSTextAlignmentRight;
        label_titleRight.text = @"mrbang888@163.com";
    }
    
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 95*PROPORTION_WIDTH;
    
}

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
        //跳转到 帮助中心
        HelpCenterVC *suggesView = [[HelpCenterVC alloc] init];
        [self.navigationController pushViewController:suggesView animated:NO];
    }

    if (indexPath.row==1) {
        SuggestViewController *suggesView = [[SuggestViewController alloc] init];
        [self.navigationController pushViewController:suggesView animated:NO];
    }
    if (indexPath.row==3) {
        //推荐有奖
        RecomAwardVC *recommendedAward = [[RecomAwardVC alloc] init];
        [self.navigationController pushViewController:recommendedAward animated:NO];
    }

    if (indexPath.row==4) {
        RXDAboutController *abountView = [[RXDAboutController alloc] init];
        [self.navigationController pushViewController:abountView animated:NO];
    }
}


#pragma mark ---- 是否开启 推送
- (void) useSendYesOrNoAction
{
    if (isOpen==NO) {
        [button_send setBackgroundImage:[UIImage imageNamed:@"send"] forState:UIControlStateNormal];
        isOpen = YES;
        return;
    }
    
    if (isOpen==YES) {
         [button_send setBackgroundImage:[UIImage imageNamed:@"unsend"] forState:UIControlStateNormal];
        isOpen = NO;
        return;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

@end
